// 跟踪上传状态
let isUploading = false;

// 监听来自popup的消息
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.type === 'uploadStarted') {
    isUploading = true;
    sendResponse({ success: true });
  } else if (message.type === 'uploadFinished') {
    isUploading = false;
    sendResponse({ success: true });
  } else if (message.type === 'checkUploadStatus') {
    sendResponse({ isUploading });
  }
  return true; // 保持消息通道开放以支持异步响应
});

// 监听标签页关闭事件
chrome.tabs.onRemoved.addListener((tabId, removeInfo) => {
  if (isUploading) {
    // 可以在这里添加取消上传的逻辑
    console.log('标签页被关闭，上传可能未完成');
    isUploading = false;
  }
}); 